package com.thinksns.sociax.photograph.gui.widgets;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.scwang.smartrefresh.layout.header.bezierradar.RippleView;
import com.thinksns.sociax.android.R;


/**
 * 底部bar
 * @author Linsr 2017年11月08日22:19:29
 */
public class BottomBar extends FrameLayout {

    public static final int FEED = 0;
    public static final int MAP = 1;
    public static final int MESSAGE = 2;
    public static final int ME = 3;

    public interface OnBottomBarListener {
        void onItemClick(int idx);

        void onAddClick();
    }

    private int[] mIds = {R.id.bar_iv_home, R.id.bar_iv_map, R.id.bar_iv_msg, R.id.bar_iv_me};
    private ImageView[] mButtons = new ImageView[mIds.length];
    private ImageView mAddButton;
    private OnBottomBarListener mListener;
    private int mCurrentIndex;

    public BottomBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View view = LayoutInflater.from(context).inflate(R.layout.view_bottom_bar,
                (ViewGroup) getRootView(), false);
        initView(view);
        addView(view);
    }

    public void setBottomBarListener(OnBottomBarListener listener) {
        mListener = listener;
    }

    private void initView(View view) {
        for (int i = 0; i < mIds.length; i++) {
            int j = i;
            mButtons[j] = (ImageView) view.findViewById(mIds[i]);
            mButtons[j].setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener != null) {
                        if (mCurrentIndex == j) {
                            return;
                        }
                        setItemStatus(j);
                        mListener.onItemClick(j);
                        mCurrentIndex = j;
                    }
                }
            });
        }
        mAddButton = (ImageView) view.findViewById(R.id.bar_iv_add);
        mAddButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onAddClick();
                }
            }
        });

    }

    public void setItemStatus(int idx) {

    }

    public int getCurrentIndex() {
        return mCurrentIndex;
    }

    public BottomBar(Context context) {
        this(context, null, 0);
    }

    public BottomBar(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

}
